import type { UploadUserFile } from "element-plus";

export interface GetSpuListParams {
  page: number;
  limit: number;
  category3Id: number;
}

/*
  {
    "records": [
      {
        "id": 6,
        "spuName": "S10 Pro",
        "description": "产品名称\nS10 Pro\n品牌\nvivo\n首销日期\n以官网信息为准\n入网型号\nV2121A\n上市年份\n2021年\n上市月份\n7月",
        "category3Id": 61,
        "tmId": 6,
        "spuSaleAttrList": null,
        "spuImageList": null
      }
    ],
    "total": 6,
    "size": 1,
    "current": 1,
    "searchCount": true,
    "pages": 6
  }
*/
export interface SpuSaleAttrValueItem {
  baseSaleAttrId: number;
  id?: number;
  isChecked?: string;
  saleAttrName?: string;
  saleAttrValueName: string;
  spuId?: number;
}

export type SpuSaleAttrValueList = SpuSaleAttrValueItem[];

export interface SpuSaleAttrItem {
  baseSaleAttrId: number;
  id?: number;
  saleAttrName: string;
  spuId?: number;
  isShowEdit?: boolean;
  spuSaleAttrValueList: SpuSaleAttrValueList;
}
export type SpuSaleAttrList = SpuSaleAttrItem[];

export interface SpuItem {
  id?: number; // 添加spu不需要id
  spuName: string;
  tmId?: number; // 组件tmId初始化undefined
  description: string;
  // spuImageList: [
  //   {
  //     id: 0;
  //     imgName: "string";
  //     imgUrl: "string";
  //     spuId: 0;
  //   }
  // ];
  spuSaleAttrList: SpuSaleAttrList;
  category3Id?: number;
}

export interface SpuImageItem {
  id?: number;
  imgName: string;
  imgUrl: string;
  spuId?: number;
  isDefault?: string;
}
export type SpuImageList = SpuImageItem[];

// 添加或更新spu参数类型
export interface AddOrUpdateSpuParams extends SpuItem {
  spuImageList: SpuImageList;
}

// 组件使用 SpuFormData 类型
export interface SpuFormData extends SpuItem {
  spuImageList: UploadUserFile[];
}

export type SpuList = SpuItem[];

export interface GetSpuListResponse {
  records: SpuList;
  total: number;
  // 用不上的参数可以不定义类型
  // size: number;
  // current: number;
  // searchCount: boolean;
  // pages: number;
}

export interface BaseSaleAttrItem {
  id: number;
  name: string;
}

export type BaseSaleAttrList = BaseSaleAttrItem[];

/*
  SpuList 数据展示
    {
      id: number;
      spuName: string;
      description: string;
    }
  AddOrUpdateSpu 
    添加SPU参数类型
      {
        "category3Id": 0,
        "spuName": "string",
        "tmId": 0,
        "description": "string",
        "spuImageList": [
          {
            "imgName": "string",
            "imgUrl": "string",
          }
        ],
        "spuSaleAttrList": [
          {
            "baseSaleAttrId": 0,
            "saleAttrName": "string",
            "spuSaleAttrValueList": [
              {
                "baseSaleAttrId": 0,
                "saleAttrValueName": "string",
              }
            ]
          }
        ],
      }
    修改SPU参数类型
      {
        "category3Id": 0,
        "description": "string",
        "id": 0,
        "spuImageList": [
          {
            "id": 0,
            "imgName": "string",
            "imgUrl": "string",
            "spuId": 0
          }
        ],
        "spuName": "string",
        "spuSaleAttrList": [
          {
            "baseSaleAttrId": 0,
            "id": 0,
            "saleAttrName": "string",
            "spuId": 0,
            "spuSaleAttrValueList": [
              {
                "baseSaleAttrId": 0,
                "id": 0,
                "isChecked": "string",
                "saleAttrName": "string",
                "saleAttrValueName": "string",
                "spuId": 0
              }
            ]
          }
        ],
        "tmId": 0
      }
    组件使用spuFormData表单数据类型
      {
        "spuName": "string",
        "tmId": 0,
        "description": "string",
        "spuImageList": [ // 有差别
          {
            "name": "string",
            "url": "string",
            "response": {
              data: 'xxx'
            }
          }
        ],
        "spuSaleAttrList": [
          {
            "baseSaleAttrId": 0,
            "saleAttrName": "string",
            "isShowEdit": "boolean", // 有差别
            "spuSaleAttrValueList": [
              {
                "baseSaleAttrId": 0,
                "saleAttrValueName": "string",
              }
            ]
          }
        ],
      }
*/
